package com.abner.design.patterns.factory.absfactory.order;

import com.abner.design.patterns.factory.absfactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


/**
 * 披萨店(抽象工厂模式)
 * @author abner
 */
public class OrderPizza {

	public OrderPizza(AbsFactory absFactory) {
		setFactory(absFactory);
	}

	private void setFactory(AbsFactory absFactory) {
		Pizza pizza = null;
		do {
			pizza = absFactory.makePizza(getType());
			if(pizza != null) {
				pizza.prepare();
				pizza.bake();
				pizza.cut();
				pizza.box();
			}else {
				break;
			}
		}while (true);

	}

	/**
	 * 获取控制台输入的披萨
	 * @return
	 */
	private String getType() {
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("input pizza type:");
			String str = in.readLine();
			return str;
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}

}
